package com.ruoyi.web.controller.outbound;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.outbound.outbound.domain.Outbound;
import com.ruoyi.outbound.outbound.service.IOutboundService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单Controller
 * 
 * @author zzx
 * @date 2024-02-21
 */
@RestController
@RequestMapping("/system/outbound")
public class OutboundController extends BaseController
{
    @Autowired
    private IOutboundService outboundService;

    /**
     * 查询出库单列表
     */
    @PreAuthorize("@ss.hasPermi('system:outbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(Outbound outbound)
    {
        startPage();
        List<Outbound> list = outboundService.selectOutboundList(outbound);
        return getDataTable(list);
    }

    /**
     * 导出出库单列表
     */
    @PreAuthorize("@ss.hasPermi('system:outbound:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Outbound outbound)
    {
        List<Outbound> list = outboundService.selectOutboundList(outbound);
        ExcelUtil<Outbound> util = new ExcelUtil<Outbound>(Outbound.class);
        util.exportExcel(response, list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:outbound:query')")
    @GetMapping(value = "/{containerNumber}")
    public AjaxResult getInfo(@PathVariable("containerNumber") String containerNumber)
    {
        return success(outboundService.selectOutboundByConsignmentId(containerNumber));
    }
    /**
     * 审核出库单
     */
    @PreAuthorize("@ss.hasPermi('storage:tickets:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/audit/{containerNumbers}")
    public AjaxResult updateAudit(@PathVariable("containerNumbers") String[] containerNumbers)
    {
        return outboundService.updateAudit(containerNumbers);
    }
    /**
     * 反审核出库单
     */
    @PreAuthorize("@ss.hasPermi('storage:tickets:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/unaudit/{containerNumbers}")
    public AjaxResult updateUnAudit(@PathVariable("containerNumbers") String[] containerNumbers)
    {
        return outboundService.updateUnAudit(containerNumbers);
    }
    /**
     * 新增出库单
     */
    @PreAuthorize("@ss.hasPermi('system:outbound:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Outbound outbound)
    {
        return toAjax(outboundService.insertOutbound(outbound));
    }

    /**
     * 修改出库单
     */
    @PreAuthorize("@ss.hasPermi('system:outbound:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Outbound outbound)
    {
        return toAjax(outboundService.updateOutbound(outbound));
    }

    /**
     * 删除出库单
     */
    @PreAuthorize("@ss.hasPermi('system:outbound:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consignmentIds}")
    public AjaxResult remove(@PathVariable String[] consignmentIds)
    {
        return toAjax(outboundService.deleteOutboundByConsignmentIds(consignmentIds));
    }
}
